package mvc;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mvc.action.LoginAction;
import mvc.action.ZhuceAction;
import mvc.business.SomeAction;
import mvc.form.Action;
import mvc.form.ActionForm;
import mvc.form.LoginForm;
import mvc.form.ZhuceForm;
import mvc.unti.FullBean;

public class ActionServlet extends HttpServlet{

    /**
	 * 
	 */
	private static final long serialVersionUID = -8546128923857009898L;

	public ActionServlet() {
        
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
		ActionForm form = (ActionForm)(new FullBean()).full(request);
		Action action  = null;
		if ("mvc.form.LoginForm".equals(request.getParameter("sign"))){
			action = new LoginAction();
		}
		if ("mvc.form.ZhuceForm".equals(request.getParameter("sign"))){
			action = new ZhuceAction();
		}
		if ("mvc.business.SomeForm".equals(request.getParameter("sign"))){
			action = new SomeAction();
		}
		String message = action.execute(form);
		PrintWriter writer = response.getWriter();
		writer.println(message);
		writer.flush();
		writer.close();
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doGet(request, response);
	}

}
